<template>
  <slot></slot>
</template>

<script setup lang="ts">
import { provide, ref } from 'vue'
const formItemStateList: Array<{ prop: string; validate: () => boolean }> = []
provide('_validates', formItemStateList)

defineExpose({
  validate() {
    console.log('检查', formItemStateList)
    if (formItemStateList.length === 0) return true
    return !formItemStateList.map(({ validate }) => validate()).includes(false)
  },
  validateFields(fields: string[]) {
    if (fields != null) {
      return !fields.map((field) => formItemStateList.find((item) => item.prop === field)!.validate()).includes(false)
    }
    return true
  }
})
</script>

<style scoped lang="scss"></style>
